#include <opencv2/opencv.hpp>
#include <iostream>
#include <vector>

using namespace cv;
using namespace std;

int main()
{
Mat image=imread("/home/lwj/opencv.21/0.jpg");
if(image.empty())
{
    cout<<"no"<<endl;
    return -1;
}
Mat img;
resize(image,img , Size(640, 640));
imshow("原图",img);
Mat gray;
cvtColor(img,gray,COLOR_BGR2GRAY);//灰度
GaussianBlur(gray,gray,Size(3,3),2,2);//高斯滤波
//检测圆形
vector<Vec3f> circles; 
double dp=2;//缩小一半，等于1则不变
double minDist=100;//两个圆心间的最小距离
double param1=100;//Canny 边缘检测的较大阑值
double param2=100;//圆检测阀值
int min_radius=20;//圆半径最小值
int max_radius=100;//圆半径最大值
HoughCircles(gray,circles,HOUGH_GRADIENT,dp,minDist,
param1,param2,min_radius,max_radius);//
//图像中标记出圆形
for(size_t i=0;i<circles.size();i++)
{
    Point center(cvRound(circles[i][0]),cvRound(circles[i][1]));//圆心
    int radius=cvRound(circles[i][2]);//半径

    circle(img,center,3,Scalar(0,255,0),-1,8,0);//实心圆作圆心
    circle(img,center,radius,Scalar(0,0,255),3,8,0);//画圆

}

 imshow("圆检测结果",img);
    waitKey(0);
    return 0;
}